import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyEditorSupport;
import java.util.Arrays;

/**
 * @author wangxiyue@cyou-inc.com
 * @date 2020-01-09
 * @since 1.0.0
 */
public class Demo {

    public static void main(String[] args) throws IntrospectionException {
        BeanInfo beanInfo = Introspector.getBeanInfo(Person.class);
        Arrays.stream(beanInfo.getPropertyDescriptors()).forEach(
                propertyDescriptor -> {
                    propertyDescriptor.setPropertyEditorClass(StringToIntegerPropertyEditor.class);
                }
        );

    }

    static class StringToIntegerPropertyEditor extends PropertyEditorSupport {
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            Integer integer = Integer.valueOf(text);
            setValue(integer);

        }
    }

}
